package edu.scut.ga.opf.dc;
import org.jenetics.Chromosome;
import org.jenetics.FitnessFunction;
import org.jenetics.Float64Gene;
import org.jenetics.Genotype;

import com.interpss.opf.OpfNetwork;

// TODO: 如何判断哪些变量是待优化的变量；
// TODO: Float64Gene每个基因的取值是否都在0~1之间；
// TODO: 改成对ieee格式的网络，调整发电机出力使其总网损最小

// Fitness function calculator, used to calculate total generation cost
public class TVCCalculator implements FitnessFunction<Float64Gene, Double> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7750318343063305922L;
	
	private final OpfNetwork opfNetwork;
	
	// Constructor to initialise the network before optimised
	public TVCCalculator(OpfNetwork opfNetwork) {
		super();
		this.opfNetwork = opfNetwork;
	}


	@Override
	public Double evaluate(Genotype<Float64Gene> genotype) {
		final Chromosome<Float64Gene> variables = genotype.getChromosome();
		
		// 1. Modify the backbone network to fit current chromosome
		// 1.1. Initialise network object
		OpfNetwork modifiedOpfNetwork = opfNetwork;
		
		// 1.2. Use current information in the gene to modify the original network
		for (int i = 0; i < variables.length(); i++) {
			
		}
		
		// 2. Return the total costs
		return modifiedOpfNetwork.getMinTotalVariableCost() + modifiedOpfNetwork.getTotalFixedCost();
	}

}